<template>
	<view>
		<view>
			<view class="por" style="margin-bottom: -10px;">
				<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/hx.png" style="width: 100px; position: relative; z-index:4;margin: auto;text-align: center;left: 50%;top: 0;margin-left: -50px;" mode="widthFix"></image>
			</view>
		</view>
		<view class="flex j-t">
			<view class="flex a-t" style="margin-right: -5px;">
				<view class="f12 c6" style="line-height: 24px;">
					我{{vuex_user_content.word_one}}她<text class="f16 fb b"> {{vuex_MyCount.my_sign_count}} </text>天
				</view>
				<view>
					<image :src="vuex_user_content.my_avatar" style="width: 40px;border-radius: 50%; border: #fff solid 2px ; box-sizing: border-box;height: 40px; " mode=""></image>
				</view>
			</view>

			<view class="flex a-t" style="margin-left: -5px;">
				<view>
					<image :src="vuex_user_content.ta_nickname" style="width: 40px;border-radius: 50%; border: #fff solid 2px ; box-sizing: border-box;height: 40px; " mode=""></image>
				</view>
				<view class="f12 c6" style="line-height: 24px;">
					他{{vuex_user_content.word_one}}我<text class="f16 fb b"> {{vuex_MyCount.ta_sign_count}} </text>天
				</view>

			</view>
		</view>
		<view>
			<!-- <u-button  open-type="share" style="" type="success" shape="circle">确定</u-button> -->
			<button open-type="share" class="button f12" style="width: 100px; line-height:30px;text-align: center;margin:10px auto 0 auto;">
				去提醒ta
			</button>
			<!-- <view class="button f12" style="width: 100px; line-height:30px;text-align: center;margin:10px auto 0 auto;">

			</view> -->
			<view class="f12 c6" style="text-align: center;">
				今天ta还没来呢~
			</view>
		</view>
		<view >
			<view style="text-align: center;margin-top: 20px;" class="f16 fb">
				{{nian}}
			</view>
			<view class="flex a-t" style="margin-top: 10px;">
				<view v-for="(item,index) in dayslist" class="flex a-t j-t" style="width: 14.2%;margin-top: 10px;">
					<!-- <view  class="flex a-t j-t" style="position: relative;width: 100%;text-align: center;line-height: 40px;color: #fa1e8a;">

						<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/buxin.png" style="width: 84%;" mode="widthFix"></image>
						<view style="position: absolute;z-index: 1;width: 100%;height: 100%;top: 0;left: 0;">
							补
						</view>
					</view> -->
					<!-- {{days.my_sign_date.indexOf(index)!=-1}} -->
					<!-- 有一人签到 -->
					<!-- <view> -->
					<view  @click="buqian(item.day)" v-if="item.type==-1" class="xinbg flex a-t j-t">
						<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/sx.png" style="width: 70%;" mode="widthFix"></image>
					</view>

					<!-- 全部已签到 -->
					<view v-else-if="days.my_sign_date.indexOf(item.day)!=-1&&days.ta_sign_date.indexOf(item.day)!=-1" class="flex a-t j-t" style="position: relative;width: 100%;text-align: center;line-height: 40px;color: #fa1e8a;">
						<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/hx.png" style="width: 90%;" mode="widthFix"></image>
						<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/baixin.png" style="width: 70%;position: absolute;z-index: 1;left: 15%;" mode="widthFix"></image>
						<view style="position: absolute;z-index: 2;width: 100%;height: 100%;top: 0;left: 0;font-size: 12px;">已想</view>
					</view>

					<view @click="buqian(item.day)" v-else class="flex a-t j-t" style="position: relative;width: 100%;text-align: center;line-height: 40px;color: #fa1e8a;">
						<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/banhx.png" style="width: 90%;" mode="widthFix"></image>
						<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/baixin.png" style="width: 70%;position: absolute;z-index: 1;left: 15%;" mode="widthFix"></image>
						<view style="position: absolute;z-index: 2;width: 100%;height: 100%;top: 0;left: 0;">补</view>
					</view>

					<!--<view @click="buqian(item.day)" v-if="days.my_sign_date.indexOf(index+1)!=-1 && days.ta_sign_date.indexOf(index+1)!=-1" class="flex a-t j-t" style="position: relative;width: 100%;text-align: center;line-height: 40px;color: #fa1e8a;">
						<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/banhx.png" style="width: 90%;" mode="widthFix"></image>
						<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/baixin.png" style="width: 70%;position: absolute;z-index: 1;left: 15%;" mode="widthFix"></image>
						<view style="position: absolute;z-index: 2;width: 100%;height: 100%;top: 0;left: 0;">补</view>
					</view>-->


				</view>

			</view>
		</view>

		<u-popup v-model="show" mode="center">
				<view style="width: 300px;padding: 20px;">
					<view class="flex a-t j-t">
						<view @click="sele(0)" :class="num==0?'c':''" style="margin-right: 30px;">
							帮我补签
						</view>
						<view @click="sele(1)"  :class="num==1?'c':''">
							帮Ta补签
						</view>
					</view>
					<view style="text-align: center;line-height: 50px;">
					{{daydate}}
					</view>
					<view style="width: 140px;margin:auto;">
						<button @click="buqians" class="button cfff">
							{{isqiandao?'已签到':'立即补签'}}
						</button>
					</view>
				</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dayslist:[],
				nian:'',
				days:[],
				show:false,
				num:0,
				daydate:'',
				isqiandao:false,
				ist:false
			}
		},
		onLoad() {
			// this.date.getdate()
			this.nian=this.date.getYear()
			uni.setNavigationBarColor({
			    frontColor: '#000000',
			    backgroundColor: '#ffffff',
			})
			this.getdays()
		},
		onShareAppMessage(res) {
		   if (res.from === 'button') {// 来自页面内分享按钮
		     console.log(res.target)
		   }
		   return {
		     title: '快来和我一起打卡吧',
			 path:'/pages/content/content'
		   }
		 },
		methods: {
			sele(e){
				// let ist=this.isqiandao
				if(this.ist){
					e==0?this.isqiandao=true:this.isqiandao=false
				}
				this.num=e
			},
            buqian(e) {
                let e1 = e < 10 ? '0' + e : e
                this.daydate = this.date.getYear1() + '-' + e1
				console.log(this.days.my_sign_date);
                if (this.date.GetDateStr(0) == this.daydate) {
                    let test = this.days.my_sign_date.indexOf(e) != -1 ? '您今天已经想过' : '去首页签到吧';
                    uni.showToast({
                        title: test,
                        icon: "none"
                    })
                    return false
                }
                this.days.my_sign_date.indexOf(e) != -1 ? this.isqiandao = true : this.isqiandao = false
                this.ist = this.isqiandao
                this.show = true
            },
			async buqians(){
				if(this.isqiandao){
					return uni.showToast({
						title:'您已签到',
						icon:'none'
					})
				}
				var user_id=-1
				if(this.num==0){
					user_id=this.vuex_user_content.my_user_id
				}else{
					user_id=this.vuex_user_content.ta_user_id
				}
				if(user_id==0){
					return uni.showToast({
						title:'虚拟空间不支持帮ta补签',
						icon:'none'
					})
				}
				let data={
					my_space_id:this.vuex_user_content.id,
					date:this.daydate,
					user_id:user_id
				}
				let res = await this.$u.api.ksidaka(data)
				this.getdays()
				this.show = false;
			},
			async getdays(){
                this.dayslist = [];
				  var curDate = new Date();
				/* 获取当前月份 */
				  var curMonth = curDate.getMonth();
				/*  生成实际的月份: 由于curMonth会比实际月份小1, 故需加1 */
				curDate.setMonth(curMonth + 1);
				/* 将日期设置为0, 这里为什么要这样设置, 我不知道原因, 这是从网上学来的 */
				curDate.setDate(0);
				/* 返回当月的天数 */
				let res=await this.$u.api.month({my_space_id:this.vuex_user_content.id})
				this.days=res

				for(let i=0; i<curDate.getDate(); i++){
					var data={
						day:i+1,
						type:-1
					}
					for(let t in res.my_sign_date){
						if(res.my_sign_date[t]==(i+1)){
							data.type=1
						}
					}
					for(let n in res.ta_sign_date){
						if(res.ta_sign_date[n]==(i+1)){
							data.type=1
						}
					}
					this.dayslist.push(data)
				}

				return curDate.getDate();
			}
		}
	}
</script>

<style>
	page{background: #fff;}
.por{position: relative; height:120px; width:100%}
.por::before{
	position: absolute;
	content: '';
	width: 1px;
	height: 80%;
	background: #d4237a;
	left: 50%;
	top: 20%;
}

.xinbg{
	background: #eee;
	border-radius: 50%;
	width: 40px;
	height: 40px;
}
</style>
